home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sml_nj / 93src.lha / src / runtime / cstruct.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-09  |  6.7 KB  |  282 lines

  1. /* cstruct.c
  2.  *
  3.  * COPYRIGHT (c) 1990 by AT&T Bell Laboratories.
  4.  */
  5.  
  6. #ifndef THINK_C
  7. #include <sys/param.h>  /* for NOFILE */
  8. #else
  9. #define NOFILE 69
  10. #endif
  11. #include "tags.h"
  12. #include "ml_types.h"
  13. #include "prim.h"
  14.  
  15. #ifdef __STDC__
  16. #define CONCAT(ex,suffix)    ex ## suffix
  17. #else
  18. #define CONCAT(ex,suffix)    ex/**/suffix
  19. #endif
  20.  
  21. #ifndef THINK_C
  22.  
  23. /* Exceptions are identified by (string ref) values */
  24. #define ML_EXNID(ex,name)                \
  25.     struct {                        \
  26.     int  tag;                    \
  27.     char s[(sizeof(name)+3) & ~3];            \
  28.     } CONCAT(ex,_s) =                    \
  29.     {MAKE_DESC(sizeof(name)-1, TAG_string), name};    \
  30.     int CONCAT(ex,_id0)[2] = {                \
  31.     MAKE_DESC(1, TAG_array),            \
  32.     (int)PTR_CtoML(CONCAT(ex,_s).s)}
  33.  
  34. /* A nullary exception is represented by an exn packet */
  35. #define ML_EXN(ex,name)                    \
  36.     ML_EXNID(ex,name);                    \
  37.     int CONCAT(ex,_e0)[3] = {                \
  38.     MAKE_DESC(2, TAG_record),            \
  39.     (int)PTR_CtoML(CONCAT(ex,_id0)+1),        \
  40.     (int)ML_unit}
  41.  
  42.  
  43. #else
  44.  
  45. /* THINK_C v5.0.1 cannot deal with the PTR_CtoML line of each of
  46.  * the previous two macros when expanded.  The error it gives
  47.  * is: "could not evaluate constant expression"
  48.  * So I've modified the macros and added the function
  49.  * thinkc_workaround() at the end of this file to patch things
  50.  * up; it must be called from main() at startup.            -- 4Dec92  e  */
  51.  
  52.  
  53. /* Exceptions are identified by (string ref) values */
  54. #define ML_EXNID(ex,name)                \
  55.     struct {                        \
  56.     int  tag;                    \
  57.     char s[(sizeof(name)+3) & ~3];            \
  58.     } CONCAT(ex,_s) =                    \
  59.     {MAKE_DESC(sizeof(name)-1, TAG_string), name};    \
  60.     int CONCAT(ex,_id0)[2] = {                \
  61.     MAKE_DESC(1, TAG_array),            \
  62.     (int)PTR_CtoML(0/*CONCAT(ex,_s).s*/)}
  63.  
  64. /* A nullary exception is represented by an exn packet */
  65. #define ML_EXN(ex,name)                    \
  66.     ML_EXNID(ex,name);                    \
  67.     int CONCAT(ex,_e0)[3] = {                \
  68.     MAKE_DESC(2, TAG_record),            \
  69.     (int)PTR_CtoML(0/*CONCAT(ex,_id0)+1*/),        \
  70.     (int)ML_unit}
  71.  
  72.  
  73. #endif
  74.  
  75. #ifdef THINK_C
  76. #define ASM_CLOSURE(name)                        \
  77.     extern int CONCAT(name,_a)();                    \
  78.     ML_val_t CONCAT(name,_v)[2] = {(ML_val_t)MAKE_DESC(1,TAG_record),    \
  79.                    PTR_CtoML(CONCAT(name,_a))}
  80. #else
  81. #define ASM_CLOSURE(name)                        \
  82.     extern ML_val_t CONCAT(name,_a)[];                    \
  83.     ML_val_t CONCAT(name,_v)[2] = {(ML_val_t)MAKE_DESC(1,TAG_record),    \
  84.                    PTR_CtoML(CONCAT(name,_a))}
  85. #endif
  86.  
  87. #if (CALLEESAVE > 0)
  88. #ifdef THINK_C
  89. #define ASM_CONT(name)                             \
  90.     extern int CONCAT(name,_a)();                    \
  91.     ML_val_t * CONCAT(name,_c) = (ML_val_t *)(CONCAT(name,_a))
  92.  
  93. #else
  94. #define ASM_CONT(name)                             \
  95.     extern ML_val_t CONCAT(name,_a)[];                    \
  96.     ML_val_t * CONCAT(name,_c) = (ML_val_t *)(CONCAT(name,_a))
  97.  
  98. #endif
  99. #else
  100. #define ASM_CONT(name)                            \
  101.     ASM_CLOSURE(name);                            \
  102.     ML_val_t * CONCAT(name,_c) = (ML_val_t *)(CONCAT(name,_v)+1)
  103. #endif
  104.  
  105. ASM_CLOSURE(array);
  106. ASM_CLOSURE(callc);
  107. ASM_CLOSURE(create_b);
  108. ASM_CLOSURE(create_r);
  109. ASM_CLOSURE(create_s);
  110. ASM_CLOSURE(create_v);
  111. ASM_CLOSURE(floor);
  112. ASM_CLOSURE(logb);
  113. ASM_CLOSURE(scalb);
  114. ASM_CLOSURE(try_lock);
  115. ASM_CLOSURE(unlock);
  116. ASM_CLOSURE(handle);
  117.  
  118. ASM_CONT(return);
  119. ASM_CONT(sigh_return);
  120.  
  121. #define RUNVEC_SZ    12
  122. ML_val_t runvec[RUNVEC_SZ+1] = {
  123.     (ML_val_t)MAKE_DESC(RUNVEC_SZ, TAG_record),
  124.     PTR_CtoML(array_v+1),
  125.     PTR_CtoML(callc_v+1),
  126.     PTR_CtoML(create_b_v+1),
  127.     PTR_CtoML(create_r_v+1),
  128.     PTR_CtoML(create_s_v+1),
  129.     PTR_CtoML(create_v_v+1),
  130.     PTR_CtoML(floor_v+1),
  131.     PTR_CtoML(logb_v+1),
  132.     PTR_CtoML(scalb_v+1),
  133.     PTR_CtoML(try_lock_v+1),
  134.     PTR_CtoML(unlock_v+1),
  135. };
  136.  
  137.                 /* aggregate structures of length zero */
  138. int array0_v[]      = {MAKE_DESC(0,TAG_array)};
  139. int bytearray0_v[]  = {MAKE_DESC(0,TAG_bytearray)};
  140. int realarray0_v[]  = {MAKE_DESC(0,TAG_realdarray)};
  141. int vector0_v[]     = {MAKE_DESC(0,TAG_array)};
  142.  
  143. ML_EXN(div,"Div");
  144. ML_EXN(overflow,"Overflow");
  145. ML_EXN(unboundTable,"UnboundTable");
  146. ML_EXNID(syserror,"SysError");
  147.  
  148. extern int active_procs0[];
  149. extern int collected0[];
  150. extern int collectedfrom0[];
  151. extern int times0[];
  152. extern int current0[];
  153. extern int gcmessages0[];
  154. extern int majorcollections0[];
  155. extern int minorcollections0[];
  156. extern int pstruct0[];
  157. extern int ratio0[];
  158. extern int softmax0[];
  159. extern int lastratio0[];
  160. extern int sighandler0[];
  161. extern int errstrings[];
  162. extern int externlist0[];
  163.  
  164.  
  165. #define CSTRUCT_SZ    28
  166.  
  167. #ifdef M68
  168. MACHINEID("m68");
  169. #endif
  170. #ifdef C
  171. MACHINEID("ansi-c");
  172. #endif
  173. #ifdef MIPSEL
  174. MACHINEID("mipsl");
  175. #endif
  176. #ifdef MIPSEB
  177. MACHINEID("mipsb");
  178. #endif
  179. #ifdef SPARC
  180. MACHINEID("sparc");
  181. #endif
  182. #ifdef VAX
  183. MACHINEID("vax");
  184. #endif
  185. #ifdef RS6000
  186. MACHINEID("rs6000");
  187. #endif
  188. #ifdef I386
  189. MACHINEID("i386");
  190. #endif
  191. #ifdef HPPA
  192. MACHINEID("hppa");
  193. #endif
  194.  
  195. ML_val_t cstruct[CSTRUCT_SZ+1] = {
  196.     (ML_val_t)MAKE_DESC(CSTRUCT_SZ, TAG_record),
  197.     PTR_CtoML(runvec+1),
  198.     PTR_CtoML(div_e0+1),
  199.     PTR_CtoML(overflow_e0+1),           
  200.     PTR_CtoML(syserror_id0+1),
  201.     PTR_CtoML(unboundTable_e0+1),
  202.     PTR_CtoML(active_procs0+1),
  203.     PTR_CtoML(array0_v+1),
  204.     PTR_CtoML(bytearray0_v+1),
  205.     INT_CtoML(CALLEESAVE),
  206.     PTR_CtoML(collected0+1),
  207.     PTR_CtoML(collectedfrom0+1),
  208.     PTR_CtoML(current0+1),
  209.     PTR_CtoML(datalist+1),
  210.     INT_CtoML(NOFILE),
  211.     PTR_CtoML(externlist0+1),
  212.     PTR_CtoML(gcmessages0+1),
  213.     PTR_CtoML(times0+1),
  214.     PTR_CtoML(lastratio0+1),
  215.     PTR_CtoML(machine_id.s),
  216.     PTR_CtoML(majorcollections0+1),
  217.     PTR_CtoML(minorcollections0+1),
  218. #if defined(V9) || defined(HPUX) || defined(RISCos) || defined(SGI) || defined(AUX)
  219.     INT_CtoML(3),
  220. #else
  221. #  ifdef VAX
  222.     INT_CtoML(1),
  223. #  else
  224.     INT_CtoML(2),
  225. #  endif
  226. #endif
  227.     PTR_CtoML(pstruct0+1),
  228.     PTR_CtoML(ratio0+1),
  229.     PTR_CtoML(realarray0_v+1),
  230.     PTR_CtoML(sighandler0+1),
  231.     PTR_CtoML(softmax0+1),
  232.     PTR_CtoML(vector0_v+1),
  233. };
  234.  
  235. #if defined(M68)
  236.   ASM_CLOSURE(arctan);
  237.   ASM_CLOSURE(cos);
  238.   ASM_CLOSURE(exp);
  239.   ASM_CLOSURE(ln);
  240.   ASM_CLOSURE(sin);
  241.   ASM_CLOSURE(sqrt);
  242. #endif
  243.  
  244. #if defined(M68) || defined(C)
  245. ML_EXN(ln,"Ln");
  246. ML_EXN(sqrt,"Sqrt");
  247.  
  248. #define MATHVEC_SZ    9
  249. ML_val_t mathvec[MATHVEC_SZ+1] = {
  250.     (ML_val_t)MAKE_DESC(MATHVEC_SZ, TAG_record),
  251.     PTR_CtoML(ln_e0+1),
  252.     PTR_CtoML(sqrt_e0+1),
  253.     PTR_CtoML(arctan_v+1),
  254.     PTR_CtoML(cos_v+1),
  255.     PTR_CtoML(exp_v+1),
  256.     PTR_CtoML(ln_v+1),
  257.     PTR_CtoML(sin_v+1),
  258.     PTR_CtoML(sqrt_v+1),
  259. };
  260. #endif
  261.  
  262. #ifdef THINK_C
  263. void
  264. thinkc_workaround(void)    {
  265.     /*
  266.     xxx_id0[1] = (int)PTR_CtoML(xxx_s.s);
  267.     xxx_e0[1]  = (int)PTR_CtoML(xxx_id0+1);
  268.     */
  269.     syserror_id0[1]     = (int)PTR_CtoML(syserror_s.s);
  270.     div_id0[1]          = (int)PTR_CtoML(div_s.s);
  271.     div_e0[1]           = (int)PTR_CtoML(div_id0+1);
  272.     overflow_id0[1]     = (int)PTR_CtoML(overflow_s.s);
  273.     overflow_e0[1]      = (int)PTR_CtoML(overflow_id0+1);
  274.     unboundTable_id0[1] = (int)PTR_CtoML(unboundTable_s.s);
  275.     unboundTable_e0[1]  = (int)PTR_CtoML(unboundTable_id0+1);
  276.     ln_id0[1]           = (int)PTR_CtoML(ln_s.s);
  277.     ln_e0[1]            = (int)PTR_CtoML(ln_id0+1);
  278.     sqrt_id0[1]         = (int)PTR_CtoML(sqrt_s.s);
  279.     sqrt_e0[1]          = (int)PTR_CtoML(sqrt_id0+1);
  280. }
  281. #endif
  282.